import { useNode, UserComponent } from '@craftjs/core';
import {
  BaseTable,
  type IBaseTableProps,
} from '@jeoshi-design/rex-design.data-display.core';
import { NodeBox } from '../../components/NodeBox';
import { Settings } from './settings';

export const ProTable: UserComponent<IBaseTableProps<Record<string, any>>> = ({
  ...rest
}) => {
  const { nodeId } = useNode((node) => {
    return {
      nodeId: node.id,
    };
  });

  return (
    <NodeBox id={nodeId}>
      <BaseTable {...rest} />
    </NodeBox>
  );
};

ProTable.craft = {
  displayName: 'ProTable',
  related: {
    settings: Settings,
  },
  defaultProps: {
    columns: [
      {
        title: '姓名',
        dataIndex: 'name',
        key: 'name',
      },
      {
        title: '年龄',
        dataIndex: 'age',
        key: 'age',
      },
      {
        title: '住址',
        dataIndex: 'address',
        key: 'address',
      },
    ],
  },
};
